//
//  VRImageViewController.swift
//  VPai
//
//  Created by vincentwang on 16/12/20.
//  Copyright © 2016年 viatech. All rights reserved.
//

import Foundation
import GLKit
import player360


private let TAG = "VRImageViewController"

class VRImageViewController : VRViewController {
    
    var textureImage: UIImage?
    
    private var texture: GLuint = 0
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        texture = GLHelpers.loadImageTexture(textureImage)
        vrDelegate?.setMediaTexture(texture)
    }
    
    deinit {
      //  Log.info(TAG, msg: "deinit")
        
        if texture != 0 {
            let textures: [GLuint] = [texture]
            glDeleteTextures(1, textures)
            GLHelpers.checkGlError("glDeleteTextures")
            texture = 0
        }
    }
    
    //GLKViewDelegate
    override func glkView(view: GLKView, drawInRect rect: CGRect) {
        if EAGLContext.setCurrentContext(self.context) {
            vrDelegate?.OnRendererDrawFrame(self.context, rect: rect)
           GLHelpers.checkGlError("VRImageViewController.glkView")
        }
    }
    
}
                
    
